﻿
Imports std
Imports centrosphere

Partial Public Class storageJobDistributor
    Private Shared Function result_aggregate(ByVal targetJobs() As indexedJob,
                                             ByVal inputJob As ijob,
                                             ByVal expect As Boolean) As Boolean
        aggregate_internal.assert_input(targetJobs, inputJob)
        For i As Int64 = 0 To targetJobs.Length() - 1
            If targetJobs(i).finished() AndAlso storageJob(targetJobs(i)).result = expect Then
                Return inputJob.copy(targetJobs(i))
            End If
        Next

        Return inputJob.copy(targetJobs(0))
    End Function

    Protected Shared Function one_result_success_aggregate(ByVal targetJobs() As indexedJob,
                                                           ByVal inputJob As ijob) As Boolean
        Return result_aggregate(targetJobs, inputJob, True)
    End Function

    Protected Shared Function all_result_success_aggregate(ByVal targetJobs() As indexedJob,
                                                           ByVal inputJob As ijob) As Boolean
        Return result_aggregate(targetJobs, inputJob, False)
    End Function
End Class
